<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息</title>
<%@include file="common.jsp"%>

<script type="text/javascript">
$(function() {
	$('#dgUser').datagrid({
		url : rootPath + '/user/findUserByPage',
		columns : [ [
			{field : 'ck',checkbox:true},
			{field : 'id',title : '操作', width : 80,align:'center',formatter:function(value,row,index){
				return '<a class="icon-line icon-edit" href="javascript:void(0)" onclick="openUpdateUser(\''+index+'\')" title="编辑"></a>';
			}},
			{field : 'username',title : '用户名称',width : 80,align:'center'},
			{field : 'password',title : '密码',width : 80,align:'center'},
			{field : 'phoneno',title : '手机号码',width : 80,align:'center'},
			{field : 'createtime',title : '创建时间',width : 80,align:'center'},
			{field : 'roleId',title : '角色',width : 60,align:'center'},
			{field : 'status',title : '状态',width : 60,align:'center', formatter: function (value, rec, index){
				if (value == null || value == 0) {
					return "<a title='否'><input type='checkbox' disabled=true value='"+rec.status+"'></a>";
				} else {
					return "<a title='是'><input type='checkbox' checked disabled=true value='"+rec.status+"'></a>";
				}
			}},
			{field : 'remark',title : '备注',width : 120,align:'center'}
		] ],
		toolbar : '#tbUser',
		pagination: true,
		fitColumns: true,
		striped: true,
		rownumbers: true,
		singleSelect: true
	});
});
function openUpdateUser(index){
    i = 0;
    var row = $('#dgUser').datagrid('getSelected');
    if (row) {
        openDialog('dlgUser','编辑');
        url = rootPath +'/user/updateUser';
        $('#formUser').form('load', row);
    }
}

function findUser(){
    /* 根据输入条件查询数据 */
    $('#dgUser').datagrid({
        url : rootPath + "/user/findUserByPage",
        queryParams : serializeFormObj("formFindUser")
    });
}

function deleteUser(){
    /* 获取选中数据 */
    var row = $('#dgUser').datagrid('getSelected');
    if(row){
        confirmMessager('确认是否删除',function(r){
            if(r){
                $.ajax({
                    url: rootPath +'/user/deleteUserById',
                    data: {'id':row.id},
                    success: function(result){
                        /* 弹出消息框 */
                        var data = JSON.parse(result);
                        $.messager.show({
                            title:'我的消息',
                            msg:data.data,
                            timeout:2000,
                        });
                        /* 重新加载表格 */
                        $('#dgUser').datagrid('load');
                    }
                });
            }
        })
    }
}

function openAddUser(){
    openDialog('dlgUser','新增');
    url = rootPath +'/user/addUser';
    $('#cmbdRole').combogrid({
        mode: 'remote',
        panelWidth:250,
        panelHeight:300,
        idField:'id',
        textField:'roleName',
        pagination: 'true',
        url:rootPath +'/role/findRoleByPage.do',
        columns:[[
            {field:'id',title:'角色编码',width:80,hidden:true},
            {field:'roleCode',title:'角色编码',width:80},
            {field:'roleName',title:'角色名称',width:120}
        ]]
    });

}
var url = '';
var i = 0;

var checksubmitflg  = false;

function saveUser(){
    i++;
    console.log(i);
    /* $.messager.progress(); */
    $('#formUser').form('submit',{
        url: url,
        onSubmit: function(){
            var isValid = $(this).form('validate');
            if (!isValid){
                $.messager.progress('close'); // 如果表单是无效的则隐藏进度条
            }
            return isValid; // 返回false终止表单提交
        },
        task: function(e){
            console.log(e);
            $.messager.progress('close'); // 如果提交成功则隐藏进度条
            $('#dlgUser').window('close');
            $('#dgUser').datagrid('load');
        }
    });
}
</script>
</head>
<body>
	<table id="dgUser" class="easyui-datagrid" data-options="fit:true"></table>

	<div id="tbUser">
		<div class="search-form">
			<form id="formFindUser" action="#" method="get">
				<div><input label="手机号码：" name="phoneno" class="easyui-textbox" ></div>
				<div><input label="用户名称：" name="username" class="easyui-textbox" ></div>
				<div style="height: 28px; line-height: 28px; margin-left: 10px">
					<input label="是否启用" name="status" class="easyui-checkbox" >
				</div>
				<div class="search-btn">
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width: 80px" onclick="findUser()" style="margin-left:5px">查询</a>
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" style="width: 80px" onclick="javascript:$('#formFindUser').form('reset');">重置</a>
				</div>
			</form>
		</div>
		<div class="toolBar">
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="openAddUser()">新增</a>
			<!-- <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a> -->
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="deleteUser();">删除</a>
		</div>
	</div>

	<div id="dlgUser" class="easyui-dialog" style="width: 580px; height: 320px" resizable="true" closed="true" data-options="buttons:'#btnDlgUser'">
		<div class="search-form datagrid-toolbar">
			<form id="formUser" action="#" method="post">
				<input type="hidden" name="id">
				<div><input label="手机号码：" name="phoneno" class="easyui-textbox" labelAlign="right"  data-options="required:true,validType:'phoneNum'"></div>
				<div><input name="username" class="easyui-textbox" labelAlign="right" label="用户名称：" data-options="required:true"></div>
				<div><input name="password" class="easyui-textbox" labelAlign="right" label="密码：" type="password" data-options="required:true"></div>
				<div><input id="cmbdRole" name="roleId" class="easyui-textbox" labelAlign="right" label="角色：" data-options="required:true"></div>
				<div>
					<input name="status" class="easyui-combobox" labelAlign="right" labelPosition="before" label="状态：" data-options="required:true,valueField:'code',textField:'text',data:[{code:'0',text:'否'},{code:'1',text:'是'}]" limitToList=true>
				</div>
				<div class="textarea">
					<input name="remark" class="easyui-textbox" multiline="true" style="width: 524px; height: 120px" labelAlign="right" label="备注：">
				</div>
			</form>
		</div>
	</div>
	<div id="btnDlgUser">
		<a href="#" class="easyui-linkbutton" data-options="toggle:true" onclick="saveUser()">保存</a>
		<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlgUser').window('close');">关闭</a>
	</div>
</body>
</html>